local hx__zhongjie = fk.CreateSkill {
  name = "hx__zhongjie",
  tags = { Skill.Limited, },
}

hx__zhongjie:addEffect("active", {
  name = "hx__zhongjie",
  card_num = 0,
  min_target_num = 1,
  max_target_num = 999,
  prompt = "#hx__zhongjie",
  can_use = function(self, player)
    local targets = table.filter(Fk:currentRoom().alive_players, function(p) return p ~= player end)
    for _, tar in ipairs(targets) do
      return #tar:getHandlyIds() > 0 and player:usedSkillTimes(hx__zhongjie.name, Player.HistoryGame) == 0
    end
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return to_select ~= player and #to_select:getHandlyIds() > 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:sortByAction(effect.tos)
    for _, pid in ipairs(effect.tos) do
      local to = pid
      local cardIds = {}
      local handCards = to:getHandlyIds()
      for _, card in ipairs(handCards) do
        table.insert(cardIds, card)
      end
      if #cardIds > 0 then
        room:moveCards({
          from = to,
          ids = cardIds,
          toArea = Card.DiscardPile,
          moveReason = fk.ReasonDiscard,
          proposer = player,
          skillName = hx__zhongjie.name,
        })
      end
    end
    for _, pid in ipairs(effect.tos) do
      local to = pid
      room:damage({
        from = player,
        to = to,
        damage = 2,
        damageType = fk.ThunderDamage,
        skillName = hx__zhongjie.name,
      })
    end
  end,
})

return hx__zhongjie